387C - George and Number - CodeForces Solution


greedy implementation *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int mod=1e9+7;
#define pb push_back
#define umii unordered_map<int,int>
#define umci unordered_map<char,int>
#define umcc unordered_map<char,char>
#define mii map<int,int>
#define mci map<char,int>
#define mcc map<char,char>
#define vi vector<int>
#define vvi vector<vector<int>>
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define pii pair<int,int>
#define piii pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()

int power(int x,int y){
    int value = 0;
    if(y<0) return 0;
    else if(y==0) return 1;
    else if(y==1) return x;
    else if(y%2) value = (x*(power((x*x)%mod,y/2)%mod))%mod;
    else value = power((x*x)%mod,y/2)%mod;
    return value%mod;
}


int inversemod(int x) {
    return power(x,mod-2)%mod;
}


void pp(int k){
    if(k==0)
    cout<<"NO"<<endl;
    else if(k==-1)
    cout<<-1<<endl;
    else
    cout<<"YES"<<endl;
}


int32_t main() {
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
    int tt;
    tt=1;
    // cin>>tt;
    while(tt--){
        string s;
        cin>>s;
        int n=s.size();
        vector<string>v;
        string p;
        for(int i=0;i<s.size();i++){
            if(s[i]=='0'){
                p+="0";
            }
            else{
                v.pb(p);
                p="";
                p+=char(s[i]);
            }
        }
        v.pb(p);
        int idx=1;
        p=v[0];
        for(int i=1;i<v.size();i++){
            if(p.size()<v[i].size()){
                idx=i+1;
            }
            else if(p.size()==v[i].size()){
                if(v[i][0]>p[0]){
                    idx=i+1;
                }
            }
            p+=v[i];
        }
        cout<<v.size()-idx+1<<endl;
    }
	// your code goes here
	return 0;
}
/**/


Comments

Submit
0 Comments
More Questions

1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter
151A - Soft Drinking
1352A - Sum of Round Numbers
281A - Word Capitalization
1646A - Square Counting
266A - Stones on the Table
61A - Ultra-Fast Mathematician
148A - Insomnia cure
1650A - Deletions of Two Adjacent Letters
1512A - Spy Detected